Vector¶
Vector is base class of other vector like classes. It represents a series of vectors.
InĀ [1]:
from py3d import Vector
Vector()
Out[1]:
Vector([], dtype=float64)
InĀ [3]:
Vector([0, 0, 0, 0])
Out[3]:
Vector([0, 0, 0, 0])
InĀ [5]:
Vector([1, 2, -4])
Out[5]:
Vector([ 1, 2, -4])
InĀ [7]:
Vector([1, 2, 3]).tile(2)
Out[7]:
Vector([[1, 2, 3],
[1, 2, 3]])
InĀ [9]:
import py3d
py3d.Vector([1, 2, 0, 3])
Out[9]:
Vector([1, 2, 0, 3])
InĀ [10]:
Vector([1]).tile(2)
Out[10]:
Vector([[1],
[1]])
Get unit vector
InĀ [12]:
import py3d
V32 = py3d.Vector([
[1, 3],
[2, -9],
[0.1, -3]])
V32.U
Out[12]:
Vector([[ 0.31622777, 0.9486833 ],
[ 0.21693046, -0.97618706],
[ 0.03331483, -0.99944491]])
Get length of vectors
InĀ [13]:
V32.L
Out[13]:
array([3.16227766, 9.21954446, 3.0016662 ])
InĀ [15]:
from numpy import allclose
assert allclose(V32.U.L, [[1], [1], [1]])
Get homogeneous vector
InĀ [16]:
V32.H
Out[16]:
Vector3([[ 1. , 3. , 1. ],
[ 2. , -9. , 1. ],
[ 0.1, -3. , 1. ]])
Get a series of random vectors
InĀ [18]:
import py3d
py3d.Vector.rand(2, 3, 4)
Out[18]:
Vector([[[0.99703828, 0.09771217, 0.94933087, 0.13501655],
[0.36253427, 0.91112009, 0.1030082 , 0.97323757],
[0.14134559, 0.44510516, 0.82162702, 0.1639713 ]],
[[0.81692578, 0.37519085, 0.10637058, 0.11314049],
[0.46515581, 0.81665225, 0.64186667, 0.22598582],
[0.43685295, 0.8705955 , 0.3844057 , 0.8495464 ]]])
InĀ [20]:
import py3d
py3d.Vector([[0, 0], [1, 2], [3, 4]]).diff()
Out[20]:
Vector([[1, 2],
[2, 2]])
Fill nan elements of a Vector
InĀ [22]:
import py3d
py3d.Vector([0, 1, float("nan")]).fillna(-1)
Out[22]:
Vector([ 0., 1., -1.])
Drop duplicates
InĀ [23]:
import py3d
py3d.Vector([
[1,2,1],
[2,3,4],
[1,2,1],
[5,3,4]
]).unique()
Out[23]:
Vector([[1, 2, 1],
[2, 3, 4],
[5, 3, 4]])
Read a txt file storing poses
InĀ [24]:
import py3d
py3d.read_txt("poses.txt")
Out[24]:
Vector([[ 1.00000000e+00, -3.80098575e-01, -9.24678213e-01, ..., 5.21001950e-03, -9.98936438e-01, 1.15277604e+02],
[ 9.00000000e+00, -3.34781384e-01, -9.41921870e-01, ..., 1.16255671e-02, -9.98851138e-01, 1.15261281e+02],
[ 1.40000000e+01, -2.92967993e-01, -9.55757956e-01, ..., 1.35067170e-02, -9.98854036e-01, 1.15246581e+02],
...,
[ 1.14960000e+04, -6.47337507e-01, -7.61727296e-01, ..., -2.49362162e-02, -9.99613920e-01, 1.15055190e+02],
[ 1.14980000e+04, -6.47715242e-01, -7.61434833e-01, ..., -2.38185034e-02, -9.99640595e-01, 1.15053432e+02],
[ 1.15010000e+04, -6.48288354e-01, -7.60949669e-01, ..., -2.59908046e-02, -9.99615736e-01, 1.15046860e+02]])
Write csv file
InĀ [25]:
import py3d
py3d.Vector([[1,2,3],[4,5,6]]).to_csv("tmp.csv")
Read csv file
InĀ [26]:
import py3d
py3d.read_csv("tmp.csv")
Out[26]:
Vector([[1., 2., 3.],
[4., 5., 6.]])
Read pcd file
InĀ [27]:
import py3d
py3d.read_pcd("ascii.pcd").xyz.as_point()
Out[27]:
InĀ [28]:
import py3d
pcd = py3d.read_pcd("binary.pcd")
print("min", pcd.min())
print("max", pcd.max())
pcd.xyz.as_point().paint(py3d.Color.map(pcd.z))
min [-1.09082863e+02 -4.56674919e+01 -4.33038330e+00 2.50000000e+01 1.22393358e+09] max [9.74602280e+01 8.35153122e+01 4.22846746e+00 2.55000000e+02 1.22393358e+09]
Out[28]: